home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / zapscrn.zip / ZAP.ASM < prev    next >
Assembly Source File  |  1988-12-15  |  18KB  |  586 lines

  1.  
  2. page 60,132
  3.  
  4. ; Copyright (C) 1988  Mark Adler  Pasadena, CA
  5. ; All rights reserved.
  6.  
  7.  title ZAP - screen saver for the EGA or VGA
  8.  
  9. comment #
  10.  
  11. Version history -
  12.  
  13. 1.0     18 Nov 1988     First public version
  14. 1.1     14 Dec 1988     Fixed bug in EGAZAP
  15.  
  16.  
  17. ZAP -
  18.  
  19.  ZAP is a resident utility that blanks the screen after a specified
  20.  period of inactivity.  The ZAP.ASM program actually generates two
  21.  different programs depending on the assembler options:  EGAZAP and
  22.  VGAZAP.  The first is for the IBM Enhanced Graphics Adapter or
  23.  compatibles, and the second is for IBM PS/2's, the IBM Video Graphics
  24.  Adpater, and comaptibles.  From here on, ZAP will be used to mean
  25.  EGAZAP or VGAZAP, whichever is appropriate for your hardware.
  26.  
  27.  To install ZAP, simply put the command ZAP in your AUTOEXEC.BAT file.
  28.  From then on, when there is five minutes of inactivity at the
  29.  keyboard, ZAP will blank the screen until any key (even just a shift
  30.  key) is hit.  The time can be changed with a command line option which
  31.  specifies the time in seconds.  For example:
  32.  
  33.      zap 600
  34.  
  35.  will install ZAP (if not already installed) and change the time to 10
  36.  minutes.
  37.  
  38.  You can also turn the installed ZAP on and off using ZAP.  For example:
  39.  
  40.      zap off
  41.  
  42.  will turn off the installed ZAP, so it will not blank the screen.  Then
  43.  the command:
  44.  
  45.      zap on
  46.  
  47.  will turn ZAP back on.
  48.  
  49.  ZAP can also be installed in the "off" state, awaiting a "zap on"
  50.  command, simply by using:
  51.  
  52.      zap off
  53.  
  54.  in AUTOEXEC.BAT.  You can also specify on or off along with a new
  55.  inactivity time.  For example, the command:
  56.  
  57.      zap off 600
  58.  
  59.  in AUTOEXEC.BAT will install ZAP in the off state with a 10 minute
  60.  inactivity time.  Then a subsequent "zap on" will turn it on.  The time
  61.  must be in the range of one to 3600 seconds (one hour).  Specifying a
  62.  new time does not change whether ZAP is enabled or not and turning ZAP
  63.  on or off does not change the time.  Also, the two options can be in
  64.  either order.  For example, "zap 600 off" does the same thing as the
  65.  example above.  If ZAP is already installed, subsequent invocations of
  66.  ZAP will not install it again.  If the command:
  67.  
  68.      zap
  69.  
  70.  is entered after ZAP is already installed, this has the same effect as
  71.  the command "zap on", that is it turns on ZAP if it was off.
  72.  
  73.  ZAP turns the display back on not only when any key is hit, but also if
  74.  any video BIOS calls (int 10h) are made.  Since most application
  75.  programs seem to bypass the BIOS for video, this added feature has
  76.  little effect.
  77.  
  78.  There are a few, rare programs that also completely take the keyboard
  79.  from the BIOS, in which case ZAP can no longer find out when keystrokes
  80.  occur.  An example is STSC APL (a programming language).  In this case,
  81.  ZAP will blank your display, even though you have been merrily typing
  82.  away for the last five minutes in the application.  And the only way to
  83.  get the display back on is to return to DOS (assuming you can get out
  84.  while driving the application blindfolded).  For such applications, you
  85.  should include the commands "zap off" and "zap on" in a batch file that
  86.  runs the application to disable ZAP before entering and enabling ZAP
  87.  after leaving the application.  You will quickly discover if you have
  88.  any such applications.
  89.  
  90.  This program assumes that the current display is the (only) active
  91.  display, but does not check for it either at installation or when
  92.  running.
  93.  
  94.  For the EGA, the screen is blanked by setting the number of characters
  95.  displayed to one, and the start of horizontal blanking to the first
  96.  character.  The number of displayed characters needs to be small (set
  97.  to one for convenience) since the horizontal blanking interval is
  98.  limited to 32 characters.  The screen is restored by getting the
  99.  current screen mode information from the BIOS and from that and the
  100.  table of Start Horizontal Blanking values in this program (copied from
  101.  the BIOS listing---not entirely kosher, but the only decent approach),
  102.  the proper register values are restored.
  103.  
  104.  For the VGA, the screen is blanked and restored using the Screen Off
  105.  bit in the Clocking Mode Register (port 0x3c4, address 01, bit 5).
  106.  
  107.  To minimize the resident memory required, this program is assembled
  108.  separately for the EGA or VGA.  When assembling, define the symbol EGA
  109.  or VGA in the command line using /d (see the manual for MASM or TASM).
  110.  If no symbol is defined, you will be warned and the resulting .COM file
  111.  will be asssembled for the VGA.  For example, the commands:
  112.  
  113.      tasm /dega zap
  114.      tlink /t zap,egazap
  115.      tasm /dvga zap
  116.      tlink /t zap,vgazap
  117.  
  118.  will generate EGAZAP.COM and VGAZAP.COM, assuming that you have the
  119.  Borland Turbo Assembler.
  120.  
  121.  The fact that the number of bytes in VGAZAP (666) is the same as
  122.  Reagan's retirement home's address in Bel Air should be given no
  123.  religious significance.
  124.  
  125. #
  126.  
  127. ifndef VGA
  128. ifndef EGA
  129.  %out !No display specified---assembling for the VGA.
  130. endif
  131. endif
  132.  
  133. ;
  134. ; Macros for blanking screens.
  135. ;
  136.  
  137. egaoff macro
  138.  local ismono,CRTMON,CRTCOL
  139. CRTMON equ 03B4h        ;;CRT controller register in Mono mode.
  140. CRTCOL equ 03D4h        ;;CRT controller register in Color mode.
  141.   push AX               ;;Save registers.
  142.   push BX
  143.   push CX
  144.   push DX
  145.   mov AH,12h            ;;Get Mono/Color in BH.
  146.   mov BL,10h
  147.   pushf                 ;;Do Int 10h
  148.   push CS
  149.   call altvid
  150.   mov DX,CRTMON         ;;Point DX to CRT port in Mono mode.
  151.   test BH,BH            ;;See if color mode.
  152.   jnz ismono            ;;If not, then DX is correct.
  153.    mov DX,CRTCOL        ;;If color, use color address.
  154.  ismono:
  155.   mov AX,1              ;;Set number of characters to 1.
  156.   out DX,AX
  157.   inc AX                ;;Set horizontal start of blanking to char 0.
  158.   out DX,AX
  159.   pop DX                ;;Restore registers.
  160.   pop CX
  161.   pop BX
  162.   pop AX
  163. endm
  164.  
  165. egaon macro
  166.  local ismono,enhance,shbget,tbl,CRTMON,CRTCOL
  167. CRTMON equ 03B4h        ;;CRT controller register in Mono mode.
  168. CRTCOL equ 03D4h        ;;CRT controller register in Color mode.
  169. ;;
  170. ;; Restore the display by getting the correct register values and
  171. ;; setting them.
  172. ;;
  173.         ;; save registers used by routine, except AX.
  174.   push BX
  175.   push CX
  176.   push DX
  177.         ;; get CRT port, switch setting.
  178.   mov AH,12h            ;;Get switch setting into CL, Mono/Color in BH.
  179.   mov BL,10h
  180.   pushf                 ;;Do Int 10h
  181.   push CS
  182.   call altvid
  183.   mov DX,CRTMON         ;;Point DX to CRT port in Mono mode.
  184.   test BH,BH            ;;See if color mode.
  185.   jnz ismono            ;;If not, then DX is correct.
  186.    mov DX,CRTCOL        ;;If color, use color address.
  187.  ismono:
  188.         ;; get values for CRT registers 1 and 2.
  189.   mov AH,0Fh            ;;Get mode into AL, columns into AH.
  190.   pushf                 ;;Do Int 10h
  191.   push CS
  192.   call altvid
  193.   dec AH                ;;Compute Horizontal Display End setting (1).
  194.   cmp AL,3              ;;See if color mode.
  195.   ja shbget             ;;If not, go on to get Start Horiz Blank (2).
  196.    cmp CL,3             ;;See if in secondary enhanced mode.
  197.    je enhance           ;;If so, use enhanced 0-3 settings.
  198.     cmp CL,9            ;;See if in primary enhanced mode.
  199.     jne shbget          ;;If not, use normal 0-3 settings.
  200.    enhance:
  201.      add AL,11h         ;;Add offset for table.
  202.  shbget:
  203.   mov BX,(offset trap)+(tbl-set)        ;;Point to table.
  204.   xlat byte ptr CS:tbl  ;;Get Start Horizontal Blank setting.
  205.         ;; Now AH is CRT register 1, AL is register 2 - set them.
  206.   mov CL,AL             ;;Save register 2 setting.
  207.   mov AL,1              ;;Set register 1.
  208.   out DX,AX
  209.   mov AH,CL             ;;Get register 2 setting.
  210.   inc AX                ;;Set register 2.
  211.   out DX,AX
  212.         ;; done, restore registers and return.
  213.   pop DX
  214.   pop CX
  215.   pop BX
  216.   ret
  217.         ;;Start horiz blank values for modes 0-10, 0*-3*.
  218.  tbl label byte
  219.   db 2Dh,2Dh,5Ch,5Ch,2Dh,2Dh,59h,56h            ;;0-7.
  220.   db 2Dh,2Dh,2Dh,5Ch,56h,2Dh,59h,56h,53h        ;;8-10h.
  221.   db 2Bh,2Bh,53h,53h                            ;;0*-3*.
  222. endm
  223.  
  224. vgaoff macro
  225.  local CRTS